package com.zb.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zb.entity.ZjFactoryAccountBalance;
import com.zb.mapper.ZjFactoryAccountBalanceMapper;
import com.zb.service.ZjFactoryAccountBalanceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 厂商账户余额表 服务实现类
 * </p>
 *
 * @author WEN
 * @since 2024-02-27
 */
@Service
public class ZjFactoryAccountBalanceServiceImpl extends ServiceImpl<ZjFactoryAccountBalanceMapper, ZjFactoryAccountBalance> implements ZjFactoryAccountBalanceService {
    @Resource
    private ZjFactoryAccountBalanceMapper factoryAccountBalanceMapper;

    // 保存账号余额
    @Override
    public void saveAccountBalance(Long factoryId) {
        ZjFactoryAccountBalance balance = new ZjFactoryAccountBalance();
        balance.setId(factoryId);
        balance.setMoney(new BigDecimal("0.0"));
        balance.setFreezeMoney(new BigDecimal("0.0"));
        this.saveOrUpdate(balance);
    }

    // 增加冻结品牌商家费用
    @Override
    public void updateFreezePriceById(Long id, BigDecimal freezePrice) {
        factoryAccountBalanceMapper.updateFreezePriceById(id, freezePrice);
    }

    // 根据厂商ID获取账户信息
    @Override
    public List<ZjFactoryAccountBalance> getByIds(List<Long> ids) {
        if (CollectionUtil.isEmpty(ids)) {
            return new ArrayList<>();
        }
        QueryWrapper<ZjFactoryAccountBalance> wrapper = new QueryWrapper<>();
        wrapper.select("id", "money", "freeze_money")
                .in("id", ids);
        return this.list(wrapper);
    }
}
